import { HttpAdapterHost, NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { getServerConfig } from '../ormconfig';
import { WINSTON_MODULE_NEST_PROVIDER, WinstonModule } from 'nest-winston';
import { createLogger } from 'winston';
import { AllExceptionFilter } from './filters/all-exception.filter';
import { Logger } from '@nestjs/common';
async function bootstrap() {
  // const logger = createLogger({
  //   //  一些配置项
  // });
  const config = getServerConfig();
  const port =
    typeof config['APP_PORT'] === 'string'
      ? parseInt(config['APP_PORT'])
      : 3000;
  const app = await NestFactory.create(AppModule, {
    cors: true,
    // logger: WinstonModule.createLogger(logger),
  });

  const httpAdapter = app.get(HttpAdapterHost);
  const logger = new Logger();
  app.useGlobalFilters(new AllExceptionFilter(logger, httpAdapter));
  app.useLogger(app.get(WINSTON_MODULE_NEST_PROVIDER));
  app.setGlobalPrefix('api/v1');

  await app.listen(port);
}
bootstrap();
